from utils.http_client import Http_Clien as http
from utils.process_results import Results as ok
from pyquery import PyQuery as pq
import time
from javdb.detail_page_parse import PageParse as parse
from javdb import config


class DetailPage:
    domain_url = config['domain']['javdb_url']

    # 输出详情页url
    def __init__(self, start_url):
        self.start_url = start_url

    def on_start(self):
        response = http.single_get(start_url=self.start_url)
        doc = pq(response)
        self.detail_urls = (DetailPage.domain_url + item.attr("href") for item in doc("a.box").items())
        return self  # 返回生成器

    def detail_results(self):
        tasks = [http.single_get(url) for url in self.detail_urls]
        resluts = ([parse.get_data(response=page_response) for page_response in tasks])  # 解析最终结果
        ok.print_results(resluts)
